//
//  CCYStatusVM.swift
//  03.微博
//
//  Created by 蔡承毅 on 16/9/28.
//  Copyright © 2016年 IOS. All rights reserved.
//

import UIKit

class CCYStatusVM: NSObject {
    /// 新浪返回的微博模型
    var status: CCYStatus
    
    /// 会员图片
    var vipImage: UIImage?
    
    /// 认证图片
    var verifiedImage: UIImage?
    
    /// 原创微博配图的URL
    var storePictureURLs: [URL]?
    
    
    
    init(status: CCYStatus) {
        self.status = status
        
        // 微博会员
        let mbrank = status.user?.mbrank ?? 0
        if mbrank > 0 && mbrank <= 6 {
            // 有会员等级
            let imageName = "common_icon_membership_level\(mbrank)"
            vipImage = UIImage(named: imageName)
        }else{
            vipImage = nil
        }
        
        // 认证图标
        let verified_type = status.user?.verified_type ?? -1
        switch verified_type {
        case 0:
            verifiedImage = UIImage(named: "avatar_vip")
        case 2, 3, 5:
            verifiedImage = UIImage(named: "avatar_enterprise_vip")
        case 220:
            verifiedImage = UIImage(named: "avatar_grassroot")
        default:
            verifiedImage = nil
        }
        
        let count = status.pic_urls?.count ?? 0
        
        if count > 0  {
            storePictureURLs = [URL]()
            
            // 遍历所有字典
            for dict in status.pic_urls! {
                let urlString = dict["thumbnail_pic"]
                
                let url = URL(string: urlString!)!
                
                storePictureURLs?.append(url)
            }
        }
        
    }
    override var description: String{
        get{
            return "\n\t CCYStatusVM: status = \(status)"
        }
    }
}
